package com.example.mylibrary.utils.imageutils.picassoutils;

import android.content.Context;
import android.net.Uri;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.squareup.picasso.Picasso;

import java.io.File;

/**
 * Created by qundui on 2017/4/22.
 */

public class PicassoUtils {

        public static void loadImageByurl(String url, Context ctx, ImageView imageView) {
            Picasso.with(ctx).load(url).into(imageView);

        }
        public static void loadImageByRes(int res, Context ctx, ImageView imageView) {
            Picasso.with(ctx).load(res).into(imageView);

        }
        public static void loadImageByFile(Context ctx, ImageView iv, File file) {
            Picasso
                    .with(ctx)
                    .load(file)
                    .into(iv);
        }

        public static void loadImageByURI(Context ctx, ImageView iv, int res) {
            Uri uri = resourceIdToUri(ctx, res);

            Picasso
                    .with(ctx)
                    .load(uri)
                    .into(iv);
        }

        public static final String ANDROID_RESOURCE = "android.resource://";
        public static final String FOREWARD_SLASH = "/";

        private static Uri resourceIdToUri(Context context, int resourceId) {
            return Uri.parse(ANDROID_RESOURCE + context.getPackageName() + FOREWARD_SLASH + resourceId);
        }
    }


